package yesCaptcha

import (
	"encoding/json"
	"gitee.com/kaylee595/gkaylee/kerr"
)

func TaskResultTo[T any](taskResult *RespGetTaskResult[json.RawMessage]) (*RespGetTaskResult[T], error) {
	ret := &RespGetTaskResult[T]{
		BaseResponse: taskResult.BaseResponse,
		Status:       taskResult.Status,
	}
	if len(taskResult.Solution) > 0 {
		err := json.Unmarshal(taskResult.Solution, &ret.Solution)
		if err != nil {
			return nil, kerr.WrapTraceStack(err)
		}
	}
	return ret, nil
}
